import courseConfig from '@/components/Course/Table/config'

const state = {}

const mutations = {}

const actions = {
  // 将 ajax 数据转为组件接受的格式
  transform({ commit }, rawData) {
    let result = []
    for (let i = 0; i < 13; i++) {
      result.push({
        courseNum: i + 1, startTime: courseConfig.COURSE_START_SCHEDULE[i],
        endTime: courseConfig.COURSE_END_SCHEDULE[i],
        _tb_courseNum: courseConfig.COURSE_START_SCHEDULE[i] + '^' + (i + 1)
      })
    }
    for (let item of rawData.data) {
      const cellContent = item.courseName + '^' + item.room + '^' + item.clazzNames.toString() + '*[' + item.status + ']'
      let tableKey = '_tb_' + Object.keys(courseConfig.WEEKDAY_MAPPER)[item.weekday]
      result[item.startNum - 1][tableKey] = cellContent
      result[item.endNum - 1][tableKey] = cellContent
    }
    return result
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
